package com.applcn.user.repo.repository;

import com.applcn.user.repo.entity.RoleMenuEntity;
import com.applcn.user.repo.mapper.RoleMenuMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * com.applcn.user.repo.repository
 * Description:
 *
 * @author: 大妖怪
 * @date: 2020-03-09 00:19
 */
@Repository
public class RoleMenuRepository extends ServiceImpl<RoleMenuMapper, RoleMenuEntity> {

    /**
     * 通过角色列表查询角色菜单列表，去重
     *
     * @param roleIdList
     * @return
     */
    public Set<RoleMenuEntity> getRoleMenuListByRoleIdList(List<Long> roleIdList) {
        List<RoleMenuEntity> roleMenuEntityList = baseMapper.selectList(
                new QueryWrapper<RoleMenuEntity>()
                        .lambda()
                        .in(RoleMenuEntity::getRoleId, roleIdList)
        );
        Set<RoleMenuEntity> roleMenuEntitySet = new HashSet<>();
        roleMenuEntitySet.addAll(roleMenuEntityList);
        return roleMenuEntitySet;
    }
}
